#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2021/4/23 23:43
# @Author  : LiShan
# @Email   : lishan_1997@126.com
# @File    : draw.py
# @Note    : this is note

import numpy as np
import matplotlib.pyplot as plt

def darw_reward(file):
    # 绘制奖励曲线
    reward = []
    legend = ["reward"]
    with open(file, "r") as f:
        lines = f.readlines()
    for i in range(len(lines)):
        line = lines[i].strip('\n')
        reward.append(float(line))
    # 绘图
    x = np.linspace(0, len(reward), len(reward))
    plt.plot(x, reward)
    # 设置坐标轴名称
    plt.xlabel("Step", fontproperties='Times New Roman', size=10.5)
    plt.ylabel("reward", fontproperties='Times New Roman', size=10.5)
    # 设置网格
    plt.grid()
    # 设置图例
    plt.legend(legend, loc="best", frameon=False)
    # 设置标题
    plt.title("The Reward Variation", fontproperties='SimSun', size=10.5)
    # 保存图片
    plt.savefig("reward.svg")
    # 显示图片
    plt.show()


darw_reward('./model/reward.txt')